﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MessageBox.cs" company="Marcelo Roca">
//   Copyright (c) 2011 Marcelo Roca. All rights reserved.
// </copyright>
// <author name="Marcelo Roca" email="marce@marceloroca.com"/>
// <license>
//   This program is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
// 
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program.  If not, see http://www.gnu.org/licenses/.
// </license>
// --------------------------------------------------------------------------------------------------------------------

namespace GameKits.Unity.GuiForms.Forms
{
    using Controls;
    using UnityEngine;

    public class MessageBox : Form
    {
        /// <summary>
        /// Inicializamos lso controles
        /// </summary>
        protected override void Initialize()
        {
            var newBox = new FixedBox
                                    {
                                        Text = "Hello GUI...!",
                                        Position = new Position(10, 10),
                                        Size = new Size(100, 30)
                                    };

            var newButton = new FixedButton
                                    {
                                        Text = "Close",
                                        Position = new Position(10, 150),
                                        Size = new Size(100, 25)
                                    };

            newButton.Click += delegate
                                    {
                                        this.Close(new FormEffect(1f, EffectTypes.FadeOut, EffectPivots.Center));
                                    };
            
            var newTextArea = new FixedPasswordField()
                                    {
                                        Text = string.Empty,
                                        Position = new Position(10, 50),
                                        Size = new Size(300, 70),
                                        MaskChar = 'X',
                                        MaxLenght = 5
                                    };

            newTextArea.KeyPressed += delegate(object source, KeyEventArgs e)
                                    {
                                        if (e.KeyPressed == KeyCode.Return && !e.Shift)
                                        {
                                            Debug.Log(((FixedPasswordField)source).Text);
                                            ((FixedPasswordField)source).Text = string.Empty;
                                        }
                                    };

            this.Add(newBox, newButton, newTextArea);

            this.WindowRect = new Rect(10, 10, 400, 300);
            this.Title = "Message Box";
            this.IsDraggable = true;
        }
    }
}
